﻿@{
    ViewBag.Title = "添加任务·自由飞·任务管理系统";
    Layout = "~/Views/Shared/_Layout_Dual_Columns_Big.cshtml";
}
@using Global.Core.ExtensionMethod
@section RightTitle{
    <h2>说明</h2>
}
@section Introduction{
    <ul>
        <li>1、标题不能为空，长度不超过255个字符。</li>
        <li>2、图片可以直接发布在内容里，其他格式的文件请通过附件发布。</li>
        <li>3、验收人没有指定的话，默认为发布人。</li>
        <li>4、不指定分配人，提交后任务为“发布”状态；指定分配人，提交后为“分配”状态。</li>
        <li>5、虚任务是自己没有实际工作内容，需要靠其子任务来实现其功能的任务。虚任务不能指定工时。</li>
        <li>6、不勾选“转到”，提交后页面跳转到该任务的编辑页面。</li>
        <li>7、勾选“转到”，任务创建后，页面可跳转到：以该任务为父任务的编辑页面、其他新任务的创建页面，和任务列表页面。</li>
    </ul>
}
@using FFLTask.GLB.Global.Enum
@using Global.Core.Helper
@model FFLTask.SRV.ViewModel.Task.NewModel
@using (@Html.BeginForm("New", "Task", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <h3>
        创建任务
    </h3>
    @Html.Partial("EditColumns/_Subtitle", TaskProcess.Publish)
    @Html.EditorFor(m => m.Publish, "_PublishEditable")
    <input type="hidden" name="UploadForPublish" id="UploadForPublish" />
    @Html.Partial("EditColumns/_Subtitle", FFLTask.GLB.Global.Enum.TaskProcess.Assign)
    @Html.EditorFor(m => m.Assign, "_AssignEditable")
    <div id="dual_columns_big_input_submit">
        <input type="submit" value="创建" id="dual_columns_big_input_submit_input" />
        <img alt="处理中..." src="/Resource/Image/waiting.gif" id="submitting" style="margin-top: 20px;" />
        转到：
        <label>
            @Html.RadioButtonFor(m => m.Redirect, RedirectPage.Current) 编辑
        </label> |
        <label>
            @Html.RadioButtonFor(m => m.Redirect, RedirectPage.Child)子
        </label>
        <label>
            @Html.RadioButtonFor(m => m.Redirect, RedirectPage.Brother, new { id = "redirect_brother" })兄弟
        </label>
        <label>
            @Html.RadioButtonFor(m => m.Redirect, RedirectPage.Other)其他
        </label> 任务 |
        <label>
            @Html.RadioButtonFor(m => m.Redirect, RedirectPage.List)任务列表
        </label>
    </div>
}
@if (false)
{
    <script type="text/javascript" src="/Resource/Scripts/jquery-2.1.0-vsdoc.js"></script>
}
@section JavaScript{
    <script src="@Url.Content("~/Resource/kindeditor-v4.1/kindeditor-min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Resource/kindeditor-v4.1/lang/zh_CN.js")" type="text/javascript"></script>
    <script type="text/javascript">

        var taskBodyId = "@Html.IdFor(m => m.Publish.Body)";

        var $waiting = $("#waiting");
        $waiting.hide();

        var isSubmit = false;
        window.onbeforeunload = function () {
            editorBody.sync();
            if (!isSubmit && $("#" + taskBodyId).val() != "") {
                return "页面内容还没有被保存，确认要离开？";
            }
        }

        $(document).ready(function () {

            $("#submitting").hide();

            $(".date_picker").datepicker();
            
            preventEnterSubmit();
            $("form").submit(function (event) {
                if ($("#not_find").is(":visible")) {
                    event.preventDefault();
                    return false;
                }
            });
            $("#dual_columns_big_input_submit_input").click(function () {
                isSubmit = true;
                preventDuplicatedSubmit(this);
            });

            showBrotherTask();
            $("#@Html.IdFor(x => x.Publish.Parent.Id)").blur(function () {
                showBrotherTask();
            });
        });

        function showBrotherTask() {
            if ($("#@Html.IdFor(x => x.Publish.Parent.Id)").val() == "") {
                $("#redirect_brother").parent().hide();
            }
            else {
                $("#redirect_brother").parent().show();
            }
        }

        function refreshProject(event) {
            var projectId = get_current_project_id($(event));
            canPublish(projectId);
            refreshOwner(projectId, "#@Html.IdFor(x => x.Assign.SelectedOwnerId)");
            refreshDifficulties(projectId, "#@Html.IdFor(x => x.Publish.SelectedDifficulty)");
            refreshPriority(projectId, "#@Html.IdFor(x => x.Publish.SelectedPriority)");
            refreshAccepter(projectId, "#@Html.IdFor(x => x.Publish.SelectedAccepterId)");
        }
    </script>

@*TODO: copy from /Task/Edit, don't know how to re-use!*@
<script type="text/javascript">
    $(document).ready(function () {

        var $initUpload = $(".init_upload");
        var $continueUpload = $(".continue_upload");

        $initUpload.change(uploadChange);
        $continueUpload.hide().click(function (event) {
            event.preventDefault();

            var uploadInput =
                "<input type='file' name='file' /> " +
                "<span class='reminder'>（* 页面提交时上传文件）</span>" +
                "<a href='#' class='delete_upload_file'>删除</a>" +
                "<br />";
            $(this).parent().append(uploadInput)
                .find("input[name=file]:last").change(uploadChange);

            $("a.delete_upload_file").click(function (event) {
                event.preventDefault();
                $(this).parent().next().remove();
                $(this).parent().remove();
                uploadChange();
            });

            $(this).hide();
        });

        function uploadChange() {

            var $parent = $(this).parent();
            var $continueUpload = $parent.children("a.continue_upload");

            //assume that the continue link should be shown
            $continueUpload.show();

            //but check only show continue link when all the file input has value
            $parent.children("input[name=file]").each(function () {
                if ($(this).val() == "") {
                    $continueUpload.hide();
                }
            });

            //mark the uploaded files belongs to Publish or Comment
            var $uploaded;
            var belong = $parent.attr("data-belong");
            if (belong == "Publish") {
                $uploaded = $("#UploadForPublish");
            } else if (belong == "Comment") {
                $uploaded = $("#UploadForComment");
            }
            var before = $uploaded.val();
            $uploaded.val(before + "|" + $(this).val().split("\\").pop());
        }
    });
</script>
}
